/*
 * @Author       : Hejh(3010733382@qq.com)
 * @Version      : V1.0
 * @Date         : 2024-01-29 18:14:18
 * @Description  : 角色相关
 */
import { defineStore } from 'pinia'
import { getAuthRoleByPage, getRoleByPage } from '@/api/role'
import type { RoleRes } from '@/types/role'

interface RoleStore {
  roleList: RoleRes[]
}

export default defineStore('role', {
  state(): RoleStore {
    return {
      roleList: []
    }
  },
  actions: {
    setRoleList(roleList: RoleRes[]) {
      this.roleList = roleList
    },

    async getRoleList() {
      const res = await getAuthRoleByPage()
      this.setRoleList(res.data.items)
    }
  },
  getters: {
    systemRoles(state) {
      return state.roleList.filter((item) => +item.type === 0)
    },
    docRoles(state) {
      return state.roleList.filter((item) => +item.type === 1)
    }
  }
})
